home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / VISCAFE.BIN / StreamImageSource.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-06-19  |  1.7 KB  |  62 lines

  1. package symantec.itools.db.awt;
  2.  
  3. import java.awt.image.ImageProducer;
  4. import java.io.BufferedInputStream;
  5. import java.io.InputStream;
  6. import java.net.MalformedURLException;
  7. import java.net.URL;
  8. import sun.awt.image.GifImageDecoder;
  9. import sun.awt.image.ImageDecoder;
  10. import sun.awt.image.JPEGImageDecoder;
  11. import sun.awt.image.URLImageSource;
  12.  
  13. public class StreamImageSource extends URLImageSource implements ImageProducer {
  14.    InputStream stream;
  15.    int type;
  16.    URL base;
  17.    static URL baseUrl;
  18.    public static final int GIF = 0;
  19.    public static final int JPEG = 1;
  20.  
  21.    public StreamImageSource(InputStream var1, int var2) {
  22.       this(baseUrl, var1, var2);
  23.    }
  24.  
  25.    public StreamImageSource(URL var1, InputStream var2, int var3) {
  26.       super(var1);
  27.       if (var3 != 0 && var3 != 1) {
  28.          throw new IllegalArgumentException("Unsupported image type:" + var3);
  29.       } else {
  30.          this.stream = var2;
  31.          this.type = var3;
  32.       }
  33.    }
  34.  
  35.    public static void setBaseUrl(URL var0) {
  36.       baseUrl = var0;
  37.    }
  38.  
  39.    public static URL getBaseUrl() {
  40.       return baseUrl;
  41.    }
  42.  
  43.    protected ImageDecoder getDecoder() {
  44.       BufferedInputStream var1 = new BufferedInputStream(this.stream);
  45.       switch (this.type) {
  46.          case 0:
  47.             return new GifImageDecoder(this, var1);
  48.          case 1:
  49.             return new JPEGImageDecoder(this, var1);
  50.          default:
  51.             throw new IllegalArgumentException("Unsupported image type:" + this.type);
  52.       }
  53.    }
  54.  
  55.    static {
  56.       try {
  57.          baseUrl = new URL("file://");
  58.       } catch (MalformedURLException var0) {
  59.       }
  60.    }
  61. }
  62.